package com.neuedu.shixun.hospital2.controller;

import com.neuedu.shixun.hospital2.entity.Order;
import com.neuedu.shixun.hospital2.entity.Order2;
import com.neuedu.shixun.hospital2.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("getMyOrder")
    public List<Order2> getMyOrder( Integer ddid){
        List<Order> list=new ArrayList<>();
        List<Order2> list1=new ArrayList<>();
        try{
        list=orderService.getOrderByDid(ddid);
         list1=orderService.getOrder2(list);
        }catch (Exception e){

        }
        log.info("list1"+list1);
        return  list1;
    }
    @GetMapping("getOrder")
    public List<Order2> getOrder(){
        List<Order> list=orderService.getOrder();
        List<Order2> list1=orderService.getOrder2(list);
        log.info("list1:"+list);
        return  list1;
    }
    @GetMapping("getAll")
    public List<Order2> getAll(){
        List<Order2> list=orderService.getOrder2();
        return  list;
    }
    @PostMapping("updateOrder")
    public Order updateOrder(@RequestBody Order2 order2){
        log.info("order2"+order2);
        Order order=orderService.getOrderOne(order2.getOOid(),order2.getOStatus());
        Order order1=orderService.updateOrder(order);
        log.info("order1"+order1);
     return order1;
    }
}
